package cn.hongyu.controller;

import cn.hongyu.pojo.Role;
import cn.hongyu.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/list")
    private ModelAndView list(){
        ModelAndView modelAndView = new ModelAndView();
        List<Role> list = roleService.list();
        modelAndView.addObject("list",list);
        modelAndView.setViewName("role-list");
        return modelAndView;
    }

    @RequestMapping("/save")
    public String sava(Role role){
        roleService.save(role);
        return "redirect:/role/list";
    }
    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable Long id){
        roleService.delete(id);
        return "redirect:/role/list";
    }
}
